$(function () {
  let box = $('.box')[0]
  let x0 = null
  box.addEventListener(
    'touchstart',
    function (e) {
      let touch = e.touches[0]
      x0 = touch.clientX
      console.log('box 触摸开始')
    },
    false
  )
  box.addEventListener(
    'touchend',
    function (e) {
      let touch = e.changedTouches[0]
      console.log(touch)
      let x1 = touch.clientX
      let res = x1 - x0
      console.log(res)
      if (res < 0 && Math.abs(res) > 10) {
        // 左滑动
        console.log('左滑动')
        this.style.backgroundColor = 'blue'
      }
      if (res > 0 && Math.abs(res) > 10) {
        // 右滑动
        console.log('右滑动')
        this.style.backgroundColor = 'green'
      }
      console.log('box 触摸结束')
    },
    false
  )
  box.addEventListener(
    'touchmove',
    function (e) {
      console.log('box 滑动操作')
    },
    false
  )
})
